package site.edody.dframe.configuration;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import site.edody.dframe.plugin.*;

/**
 *  单例初始化依赖管理
 * @author Dody
 */
@Configuration
public class CodeDependConfig {

    @Value("${plugins.codedepend.mavenurls:}")
    String[] mavenurls ;

    @Bean
    public CodeBasedDependencyManager  codeBasedDependencyManager (){
        return CodeBasedDependencyManager.getInstance(mavenurls);
    }

    @Bean
    public DynamicMethodInvoker dynamicMethodInvoker(CodeBasedDependencyManager codeBasedDependencyManager){
        return new DynamicMethodInvoker(codeBasedDependencyManager);
    }
    @Bean
    public DynamicJavaCompiler dynamicJavaCompiler(CodeBasedDependencyManager codeBasedDependencyManager){
        return new DynamicJavaCompiler(codeBasedDependencyManager);
    }

    @Bean
    public ClassLoaderCompatibilityHelper classLoaderCompatibilityHelper(CodeBasedDependencyManager codeBasedDependencyManager){
        return new ClassLoaderCompatibilityHelper(codeBasedDependencyManager);
    }
    @Bean
    public DynamicCodeExecutor DynamicCodeExecutor(CodeBasedDependencyManager dependencyManager,DynamicJavaCompiler dynamicJavaCompiler,DynamicMethodInvoker dynamicMethodInvoker,ClassLoaderCompatibilityHelper compatibilityHelper){
        return new DynamicCodeExecutor(dependencyManager,dynamicJavaCompiler,dynamicMethodInvoker,compatibilityHelper);
    }

}
